﻿using AntMovement.Core.Entity;
using AntMovernent.SolidTechESerialCard.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AntMovernent.SolidTechESerialCard.Domain
{
    public class HardwareUpdateDI : AntMovement.Core.IHardwareUpdate
    {
        private List<DI> _values = new List<DI>();
        private uint _nCardNo;
        private uint _index;
        public HardwareUpdateDI(ulong nCardNo, ulong index, DI[] values)
        {
            _nCardNo = (uint)nCardNo;
            _index = (uint)index;
            _values.AddRange(values);
        }

        public string Update()
        {
            uint data = 0;
            long error = SLDMV.SLDM_Get_InWord((uint)_values[0].CardNo, 0, (uint)_values[0].MdlIndex, ref data);
            if (error != 0) { return $"CardNo[{_nCardNo}] Index[{_index}] SLDM_Get_InWord ==>> {(SolidErrorCode)error}"; }
            int i = 0;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 1;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 2;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 3;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 4;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 5;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 6;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 7;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 8;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 9;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 10;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 11;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 12;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 13;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 14;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            i = 15;
            _values[i].Status = ((data >> i) & 0x01) == 1;
            return "ok";
        }
    }
}
